package mvc.views.mediators
{
	import alternativa.gui.data.DataProvider;
	import alternativa.gui.theme.defaulttheme.controls.text.TextInput;
	
	import com.greensock.TweenNano;
	import com.greensock.easing.Back;
	import com.greensock.easing.Elastic;
	
	import flash.utils.Proxy;
	
	import globals.Global;
	import globals.Url;
	
	import mvc.Notifications;
	import mvc.models.proxys.ProxyUser;
	import mvc.views.AppMainView;
	import mvc.views.frames.FrameLogin;
	import mvc.views.layers.BackgroundLayer;
	import mvc.views.layers.UILayer;
	
	import org.osmf.logging.Log;
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	public class MediatorLoginFrame extends Mediator implements IMediator
	{
		public static const NAME:String = "MediatorLoginFrame";
		
		private var _frame:FrameLogin=null;
		
		private var proxyUser:ProxyUser=null;
		public function MediatorLoginFrame(mediatorName:String=null, viewComponent:Object=null)
		{
			super(mediatorName, viewComponent);
			
			
		}
		
		public function get frame():FrameLogin
		{
			return _frame;
		}

		override public function listNotificationInterests():Array
		{
			// TODO Auto Generated method stub
			return [
				Notifications.MEDIATOR_SWITCH_TO_USER_LOGIN,
				Notifications.UI_TO_LOGIN,
				Notifications.MEDIATOR_LOGIN_SUCCESS,
				Notifications.MEDIATOR_LOGIN_ERROR
			];
		}
		
		override public function handleNotification(notification:INotification):void
		{
			// TODO Auto Generated method stub
			super.handleNotification(notification);
			
			switch(notification.getName())
			{
				case Notifications.MEDIATOR_SWITCH_TO_USER_LOGIN:
					Global.uiLayer.removeAll();
					_frame = new FrameLogin();
					Global.uiLayer.addChild(_frame);
					_frame.show();
					break;
				case Notifications.UI_TO_LOGIN:
					var data:Object = notification.getBody();
					ProxyUser.getInstance().login(data.username,data.password);
					break;
				case Notifications.MEDIATOR_LOGIN_SUCCESS:
					_frame.loginSuccess();
					sendNotification(Notifications.MEDIATOR_GOTO_CLIENT_URL,Url.USER_INFO);
					break;
				case Notifications.MEDIATOR_LOGIN_ERROR:
					var data:Object = notification.getBody();
					_frame.loginError(data);
					break;
			}
		}
		
		
	}
}